﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace TRINHTUNGLAM
{
    public partial class GPT : Form
    {
        public GPT()
        {
            InitializeComponent();
        }

        private void textBox1_TextChanged(object sender, EventArgs e)
        {

        }

        private void button1_Click(object sender, EventArgs e)
        {
            /*int a = int.Parse(txtsoa.Text);
            int b = Convert.ToInt16(txtsob.Text);
            //float c = Convert.ToSingle(txtsoc);
            int c = Convert.ToInt16(txtsoc.Text);
            double delta = b * b - 4 * a * c;*/
            if(string.IsNullOrEmpty(txtsoa.Text)){
                MessageBox.Show("Nhap lai so a");
                txtsoa.Focus();
            }
            if(string.IsNullOrEmpty(txtsob.Text)){
                MessageBox.Show("Nhap lai so b");
                txtsob.Focus();
            }
            if(string.IsNullOrEmpty(txtsoc.Text)){
                MessageBox.Show("Nhap lai so c");
                txtsoc.Focus();
            }
            double a=0;
            double b=0;
            double c=0;
            if(Double.TryParse(txtsoa.Text,out a) && Double.TryParse(txtsob.Text,out b) &&Double.TryParse(txtsoc.Text,out c))
            {
                double delta = (b * b - 4 * a * c);
                if(a==0)
                {
                    listBox1.Items.Add("ket qua x =" + (-c / b));
                    if(b==0 && c!=0)
                    {
                        listBox1.Items.Add("pt vo ngiem");
                    }
                }
                if(b==0)
                {
                    if(c>0)
                    {
                        listBox1.Items.Add("pt vo ngiem");
                    }
                    else
                    {
                        listBox1.Items.Add("pt co ngiem kep x = " + (Math.Sqrt(-c / a)));
                    }
                }
                else
                {
                    
                    listBox1.Items.Add("PT co 2 ngiem phan biet x1 = " + ((-b / (2 * a))) + "x2 = " + ((-b  / (2 * a))));
                }

            }
            else
            {
                MessageBox.Show("ban nhap sai");
            }

        }
    }
}
